/*
 * @lc app=leetcode.cn id=198 lang=javascript
 *
 * [198] 打家劫舍
 */

// @lc code=start
/**
 * @param {number[]} nums
 * @return {number}
 */
var rob = function (nums) {
  let dp = [];

  dp[0] = nums[0];

  dp[1] = Math.max(nums[0], nums[1]);

  for (let n = 2; n < nums.length; n++) {
    dp[n] = Math.max(dp[n - 1], dp[n - 2] + nums[n]);
  }

  return dp[nums.length - 1];
};

const res = rob([1, 2, 3, 1]);
console.log("🚀 ～ file: ", res);
// @lc code=end
